use Test::More tests => 9;

use strict;
use Carp;
use Data::Dumper;

use DateTime::Format::Mail;
use DateTime::Format::Strptime;
use DateTime::Cursor;

#
# setup formatters
#
my $strp_format = DateTime::Format::Strptime->new(pattern => '%T',
                                                  time_zone       => 'UTC',
                                                  on_error        => 'croak');
my $mail_format = DateTime::Format::Mail->new();

my @formatters = ($strp_format, $mail_format);

#
# exercise with them
#

# check default behavior
my $default_cursor_0 = DateTime::Cursor->new({pivot => DateTime->now()});
ok(! defined $default_cursor_0->get_formatter(), "default is undefined formatter for cursor created with a datetime without format specified");

# check behavior 
foreach my $formatter (@formatters) {
  # check with formatter defined in datetime constructor 
  my $dt_a = DateTime->now(formatter => $formatter);
  my $iter_a = DateTime::Cursor->new({pivot => $dt_a});
  ok(defined $iter_a->get_formatter(), "formatter $formatter defined in datetime constructor is visible from getter on cursor"); 
  cmp_ok("$dt_a", 'eq', "$iter_a", "formatter $formatter defined in datetime constructor is used by cursor correctly");  

  # check with formatter defined in cursor constructor
  my $dt_b = DateTime->now(); 
  my $iter_b = DateTime::Cursor->new({pivot => $dt_b, formatter => $formatter});
  ok(defined $iter_b->get_formatter(), "formatter $formatter defined in cursor constructor is visible from getter on cursor");
  my $cloned_dt_b = $dt_b->clone();
  $cloned_dt_b->set_formatter($formatter);
  cmp_ok("$cloned_dt_b", 'eq', "$iter_b", "formatter $formatter defined in cursor constructor is used by cursor correctly");
}
1;
